package wh.coach._thread;

/**
 * @author hangwen
 * @date 2023/10/17
 */
public class Main {

    public static void main(String[] args) throws InterruptedException {
        //错误case

//        //BOSS创建了一个工人
//        Thread thread = new Thread();
//        //BOSS在print
//        print(100);

        //创建了一个Print工人并且告诉他的任务是什么
        Thread worker1 = new Thread(new Print(10));
        //用lambda表达式创建工人
        Thread worker2 = new Thread(() -> print(10));

        worker1.start();
        worker2.start();

        //BOSS等待工人完成工作
        worker1.join();
        worker2.join();

        System.out.println("下班");
    }

    private static void print(final int number) {
        for (int i = 0; i < number; i++) {
            final Thread thread = Thread.currentThread();
            System.out.println(thread.getName() + " print:" + i);
        }
    }

    static class Print implements Runnable {
        int number;

        public Print(int number) {
            this.number = number;
        }

        @Override
        public void run() {
            Main.print(number);
        }
    }
}

